package com.meisupic.copyright.domain.bo;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import lombok.Data;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

/**
 * @author syncwt
 * @version V1.0
 * @Description: TODO
 * @date ${date} ${time}
 */
@Data
public class SysUser implements UserDetails {

  private Long id;

  private String userName;

  private String password;

  private String salt;

  private boolean admin;

  @Override
  public Collection<? extends GrantedAuthority> getAuthorities() {
    List<GrantedAuthority> authorities = new ArrayList<>();
    if(admin){
      authorities.add(new SimpleGrantedAuthority("role_admin"));
    }else {
      authorities.add(new SimpleGrantedAuthority("role_user"));
    }
    return authorities;
  }

  @Override
  public String getPassword() {
    return password;
  }

  @Override
  public String getUsername() {
    return userName;
  }

  @Override
  public boolean isAccountNonExpired() {
    return true;
  }

  @Override
  public boolean isAccountNonLocked() {
    return true;
  }

  @Override
  public boolean isCredentialsNonExpired() {
    return true;
  }

  @Override
  public boolean isEnabled() {
    return true;
  }
}
